#
# Launch file for playback of an audio stream or wav file.
#
import os

from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription, DeclareLaunchArgument
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import ThisLaunchFileDir, LaunchConfiguration
from launch_ros.actions import Node


def generate_launch_description():
    
    log_level = DeclareLaunchArgument('log_level', default_value='info')
    tts_model = DeclareLaunchArgument('model', default_value='fastpitch_hifigan')
    output_device = DeclareLaunchArgument('output_device', default_value='/jetson-voice/data/audio/tts_test.wav')

    tts_node = Node(package='jetson_voice_ros', node_executable='tts.py',
                        parameters=[
                            {"model": LaunchConfiguration('model')},
                        ],
                        arguments=['--ros-args', '--log-level', LaunchConfiguration('log_level')],
                        output='screen', emulate_tty=True)  
   
    audio_output = Node(package='jetson_voice_ros', node_executable='audio_output.py',
                        parameters=[
                            {"device": LaunchConfiguration('output_device')},
                            {"sample_rate": 22050},
                        ],
                        remappings=[
                            ("/voice/audio_out", "/voice/tts_audio"),
                        ],
                        arguments=['--ros-args', '--log-level', LaunchConfiguration('log_level')],
                        output='screen', emulate_tty=True)  
                        
    return LaunchDescription([
        log_level,
        tts_model,
        output_device,
        tts_node,
        audio_output,
    ])